<?=$this->renderPartial('tabNavigation', array('s_tabSelected'=>'import'));?>

<div class="clear"></div>

<div class="box">
<form
    id      = "form_import"
    name    = "form_import"
    class   = "form_input"
>
    <fieldset class="border_radius_all">
        <legend></legend>

        <div class="form_input_row text_center border_bottom_none">
            <div class="title_icon">
                <i class="fa fa-file-excel-o"></i>
            </div>
        </div><!--End file-->

        <div class="form_input_row">
            <label class="label_title">Định dạng dữ liệu</label>

            <div class="input_items">
                <input
                    id      = "rad_formatFileDefault"
                    name    = "rad_formatFile"
                    type    = "radio"
                    value   = "<?=filesLogic::DATA_FORMAT_DEFAULT;?>"
                    checked = "checked"
                    onclick = "switchFormatDisplay()"
                />
                <label for="rad_formatFileDefault">Định Dạng Mặc Định</label>

                <input
                    id      = "rad_formatFileCustom"
                    name    = "rad_formatFile"
                    type    = "radio"
                    value   = "<?=filesLogic::DATA_FORMAT_CUSTOM;?>"
                    onclick = "switchFormatDisplay()"
                />
                <label for="rad_formatFileCustom">Định Dạng Người Dùng</label>
            </div>
        </div><!--End form_input_row-->
    </fieldset>

    <fieldset id="customFormatArea" class="display_none">
        <div class="form_input_row">
            <label class="label_title">Tên bảng tính</label>

            <div class="input_item">
                <input
                    id    = "txt_sheetName"
                    name  = "txt_sheetName"
                    type  = "text"
                    value = ""
                />
            </div>
        </div><!--End form_input_row-->

        <div class="form_input_row">
            <label  class="label_title"> Dòng chứa tiêu đề cột</label>

            <div class="input_item">
                <input
                    id        = "txt_HeaderRowIndex"
                    name      = "txt_HeaderRowIndex"
                    type      = "number"
                    min       = "0"
                    max       = "99"
                    maxlength = "2"
                    value     = ""
                />
            </div>
        </div><!--End form_input_row-->
    </fieldset>

    <fieldset>
        <div class="form_input_row">
            <div class="input_item">
                <input
                    id   = "fle_uploadFile"
                    name = "fle_uploadFile"
                    type = "file"
                />
            </div>
        </div><!--End form_input_row-->

        <div class="form_input_row border_bottom_none">
            <div class="input_items">
                <input type="submit" value="upload" />
            </div>
        </div><!--End form_input_row-->
    </fieldset>
</form>

<div class="box_content" id="div_importResult">
</div><!--End box_content-->

</div><!--End box-->

<script type="text/javascript">
function switchFormatDisplay()
{
    var dataFormat = $("input[name='rad_formatFile']:checked").val();

    if ( dataFormat == <?=filesLogic::DATA_FORMAT_CUSTOM;?> ) {
        $('#customFormatArea').fadeIn("slow", "linear");
        return;
    }//End if

    $('#customFormatArea').fadeOut();
}//End switchFormatDisplay


$("form#form_import").submit( function(event)
{
    //disable the default form submission
    event.preventDefault();

    //grab all form data  
    var formData = new FormData($(this)[0]);

    //Call process by Ajax
    $.ajax({
        url         : '<?=Yii::app()->createUrl("category/execImport");?>',
        type        : 'POST',
        data        : formData,
        async       : false,
        cache       : false,
        contentType : false,
        processData : false,
        success : function(html) {
            $('#div_importResult').html(html);
        },//End success
        error: function ()
        {
            alert('Trang hiện hành không tồn tại.');
        }//End error
    });//End Ajax
});//end ajaxFileUpload
</script>